import 'package:flutter/material.dart';
import 'package:get/get_rx/get_rx.dart';
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
import 'package:get_storage/get_storage.dart';

class test_Getx_storage extends StatefulWidget {
  const test_Getx_storage({super.key});

  @override
  State<test_Getx_storage> createState() => _test_Getx_storageState();
}

class _test_Getx_storageState extends State<test_Getx_storage> {
  final tip = '默认值'.obs;
  final box = GetStorage();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('test_Getx_storage')),
        body: Column(children: [
      ObxValue((data){
        return Text(data.value) ;
      },tip),
          ElevatedButton(
              onPressed: () {
                // 读取数据
                tip.value = box.read('token');
              },
              child: Text('读取')),
          ElevatedButton(
              onPressed: () {
                // 写入数据
                box.write('token', tip.value+'1');
              },
              child: Text('写入')),
          ElevatedButton(
              onPressed: () {
                // 删除某个 key
                box.remove('token');
              },
              child: Text('删除')),
          ElevatedButton(
              onPressed: () {
                // 清空所有数据
                box.erase();
              },
              child: Text('清空'))
        ]));
  }
}
